package com.example.mecalculator;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView meTv;
    private String  meStr = "0";
    private double me = 0;
    private String meStr2 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        meTv = findViewById(R.id.me_tv);
    }

    public void meClick(View view) {

        Button button = (Button) view;
        String tStr = (String) button.getText();
        double tD = Double.parseDouble(tStr);

        if (me == 0) {
            me = tD;
            meStr = tStr;
            meTv.setText(meStr);
        } else  {
            if (meStr2 != null) {
                switch (meStr2) {
                    case "+":
                        me += tD;
                        break;
                    case "-":
                        me -= tD;
                        break;
                    case "×":
                        me *= tD;
                        break;
                    case "÷":
                        me /= tD;
                        break;
                }
                meStr = me + "";
                meTv.setText(meStr);
            }else {
                meStr += tStr;
                me = Double.parseDouble(meStr);
                meTv.setText(meStr);
            }
        }
    }

    public void meStrClick(View view) {

        Button button = (Button) view;
        String str = (String) button.getText();
        meStr2 = str;
    }

    public void cleatClick(View view) {
        meStr = "0";
        me = 0;
    }
}